﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using WPFEdit.Document;
using WPFEdit.Document.Factory;

namespace SampleApp
{
	/// <summary>
	/// Interaction logic for SampleEditor.xaml
	/// </summary>
	[DocumentEditor(typeof(StringHolder), false)]
	public partial class SampleEditor : UserControl, IDocumentEditor
	{
		private Document m_doc;
		public SampleEditor()
		{
			InitializeComponent();
			
		}

		void textBox1_TextChanged(object sender, TextChangedEventArgs e)
		{
			((StringHolder)m_doc.DocumentData).Dirty = true;
		}

		public Document Document
		{
			get { return m_doc; }
			set
			{
				m_doc = value;
				var data = (StringHolder)value.DocumentData;
				textBox1.Text = data.Data;
				textBox1.TextChanged += new TextChangedEventHandler(textBox1_TextChanged);
			}
		}

		public object ContentControl
		{
			get { return this; }
		}

		public void OnSelected()
		{
			
		}

		public bool OnSaving()
		{
			((StringHolder)m_doc.DocumentData).Data = textBox1.Text;
			return true;
		}
	}
}
